home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ETO Development Tools 4
/
ETO Development Tools 4.iso
/
Tools - Objects
/
Macintosh Programmer’s Workshop
/
MPW QR4
/
SADE 1.3b1
/
SADEScripts
/
StackCrawl
< prev
Wrap
Text File
|
1991-04-25
|
2KB
|
102 lines
# Symbolic Application Debugging Environment 1.2 Beta 2
#
# Copyright Apple Computer, Inc. 1987-1988
# All rights reserved.
###############################################################################
func StackOk()
return ((A7 & 1) = 0) ∂
&& ((BufPtr & 1) = 0) ∂
&& (A7 <= BufPtr)
end
func ReturnAddress(addr)
define instr, calladdr
# check if addr is in an executable region
callAddr := addr - 2
instr := ^unsignedword(callAddr)^
if instr = $6100 then
return callAddr # BSR with byte displacement
elseif (instr & $FFF8) = $4E90 then
return callAddr # JSR (An)
end
callAddr := addr - 4
instr := ^unsignedword(callAddr)^
if instr = $6100 then
return callAddr # BSR with word displacement
elseif (instr & $FFF8) = $4EA8 then
return callAddr # JSR (disp, An)
elseif (instr & $FFF8) = $4EB0 then
return callAddr # JSR (disp, An, Dn)
elseif instr = $4EBA then
return callAddr # JSR (disp, PC)
elseif instr = $4EBB then
return callAddr # JSR (disp, PC, Dn)
elseif instr = $4EB8 then
return callAddr # JSR (xxxx).W
end
callAddr := addr - 6
instr := ^unsignedword(callAddr)^
if instr = $4EB9 then
return callAddr # JST (xxxx).L
end
return 0 # not a return addr
end
func FrameOwner(addr)
define i, name := where(addr)
if length(name) = 0 then
name := '???'
else
for i := 1 to length(name) do
if copy(name, i, 1) = '+' then
name := copy(name, 1, i - 1)
leave
end
end
end
name := concat(name, copy(' ', 1, 18 - length(name)))
return name
end
proc ShowLastFrame(thisPc)
printf "<main> %t\n", FrameOwner(thisPc)
end
proc ShowFrame(thisA6, thisPC)
define callAddr, retAddr, nextA6, validFrame, name
nextA6 := thisA6^
retAddr := (thisA6 + 4)^
validFrame := ((nextA6 & 1) = 0) && ∂
(nextA6 > thisA6) && ∂
(nextA6 <= (BufPtr - 8))
printf "%.8X %t", thisA6, FrameOwner(thisPC)
if (callAddr := ReturnAddress(retAddr)) <> 0 then
name := where(callAddr)
if length(name) = 0 then
printf "%.8X\n", callAddr
else
printf "%t\n", where(callAddr)
end
else
printf "\n"
end
if validFrame then
ShowFrame(nextA6, retAddr)
else
ShowLastFrame(retAddr)
end
end
proc StackCrawl
if not StackOk() then
printf "Bad Stack\n"
elseif ((A6 & 1) = 0) && (A6 >= A7) && (A6 <= (BufPtr - 8)) then
printf "Stack frames using A6 links\n"
printf "SF Addr SF Owner Called From\n"
ShowFrame(A6, PC)
else
printf "A6 stack frame error\n"
end
end